package com.zyd.work.dao.impl;

import java.util.List;

import org.springframework.stereotype.Repository;

import com.zyd.common.DateTools;
import com.zyd.common.GenericHibernateDao;
import com.zyd.work.dao.IDayLogDAO;
import com.zyd.work.domain.vo.DayLog;

@Repository("dayLogDAOImpl")
public class DayLogDAOImpl extends GenericHibernateDao implements IDayLogDAO {

	@Override
	public void addDayLog(DayLog daylog) {
		this.create(daylog);

	}

	@Override
	public void updateDayLog(DayLog daylog) {
		this.update(daylog);
	}

	@Override
	public void deleteDayLog(String id) {
		this.bulkUpdate("delete from DayLog t where t.id=?",
				new Object[] { id });
	}

	@Override
	public List<DayLog> getAllList() {
		return this.find("from DayLog t");
	}

	@Override
	public List<DayLog> getListByUserid(String userid) {
		return this.find("from DayLog t where t.userid=?", userid);
	}

	@Override
	public DayLog getDayLogById(String id) {
		return (DayLog) this.findById(new DayLog(), id);
	}

	@Override
	public List<DayLog> getListByDate(String date, String userid) {
		return this.find("from DayLog t where t.workdate = ? and t.userid=?",
				new Object[] { DateTools.stringToDate(date), userid });
	}

	@Override
	public List<DayLog> searchDaylog(String startdate, String enddate,
			String userid) {
		return this
				.find("from DayLog t where t.workdate >= ? and t.workdate <=? and t.userid=? order by t.workdate desc",
						new Object[] { DateTools.stringToDate(startdate),
								DateTools.stringToDate(enddate), userid });
	}

}
